This package implements various tests, visualizations, and metrics for use with environmental niche models (ENMs) and species distribution models (SDMs).
Warren, D.L., N. Matzke, M. Cardillo, J. Baumgartner, L. Beaumont, N. Huron, M. Simões, Teresa L. Iglesias, and R. Dinnage. 2019. ENMTools (Software Package). URL: https://github.com/danlwarren/ENMTools. doi:10.5281/zenodo.3268814
At present, ENMTools is downloadable from https://github.com/danlwarren/ENMTools. There are multiple ways to download it. The easiest is to use devtools and install from GitHub.
Run the following code from your R console:
install.packages("devtools")
library(devtools)
install_github("danlwarren/ENMTools")
library(ENMTools)
A zipped version of the package is available at https://github.com/danlwarren/ENMTools/archive/master.zip. To install from the zip file, download a copy of it to your system. Once it’s finished downloading, type the following (where PATH is the path to the zip file):
install.packages("devtools")
library(devtools)
install_local("PATH")
library(ENMTools)
First we’re going to load in some environmental data.
env.files <- list.files(path = "./testdata/", pattern = "pc", full.names = TRUE)
env <- stack(env.files)
names(env) <- c("pc1", "pc2", "pc3", "pc4")
env <- setMinMax(env)
ENMTools is primarily designed to examine patterns of similarity and difference between ENMs for different species. In order to simplify interactions with the functions in ENMTools, you need to put your data for each of your species into an enmtools.species object. You can create and view an empty enmtools.species object just by typing:
ahli <- enmtools.species()
ahli
##
##
## Range raster not defined.
##
## Presence points not defined.
##
## Background points not defined.
##
## Species name not defined.
You can add data to this object manually:
names(ahli)
## [1] "range" "presence.points" "background.points"
## [4] "models" "species.name"
ahli$species.name <- "ahli"
ahli$presence.points <- read.csv("./testdata/ahli.csv")[,2:3]
ahli$range <- background.raster.buffer(ahli$presence.points, 50000, mask = env)
ahli$background.points <- background.points.buffer(points = ahli$presence.points,
radius = 20000, n = 1000, mask = env[[1]])
ahli
##
##
## Range raster:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## crs : NA
## source : memory
## names : pc1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -80.0106 21.8744
## -79.9086 21.8095
## -79.8065 21.7631
## -79.8251 21.8095
## -79.8807 21.8374
## -79.9550 21.8374
## -80.3446 22.0136
## -80.2983 21.9951
## -80.1776 21.9023
## -80.1591 21.9673
##
##
## Background points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -80.00392 21.94587
## -80.46226 22.14587
## -79.94559 22.05420
## -80.28726 22.16254
## -79.72892 21.77920
## -79.92892 22.07920
## -79.75392 21.84587
## -80.08726 21.91254
## -79.98726 21.72920
## -79.90392 21.99587
##
##
## Species name: ahli
Or you can add bits of it when the object is created:
allogus <- enmtools.species(species.name = "allogus",
presence.points = read.csv("./testdata/allogus.csv")[,2:3])
allogus$range <- background.raster.buffer(allogus$presence.points, 50000, mask = env)
allogus$background.points <- background.points.buffer(points = allogus$presence.points,
radius = 20000, n = 1000, mask = env[[1]])
allogus
##
##
## Range raster:
## class : RasterLayer
## dimensions : 418, 1535, 641630 (nrow, ncol, ncell)
## resolution : 0.008333333, 0.008333333 (x, y)
## extent : -86.90809, -74.11642, 19.80837, 23.2917 (xmin, xmax, ymin, ymax)
## crs : NA
## source : memory
## names : pc1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -79.2527 22.2109
## -78.7774 22.2241
## -78.6189 22.2373
## -78.1039 21.1809
## -78.0247 21.1809
## -77.9983 20.9301
## -77.9719 21.7091
## -77.9719 21.5507
## -77.9323 21.6167
## -77.9323 20.7320
##
##
## Background points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -77.97059 21.62920
## -75.63726 20.24587
## -77.82892 21.79587
## -76.91226 20.03754
## -75.07892 20.61254
## -75.52892 20.12920
## -74.73726 20.07087
## -76.86226 20.25420
## -77.75392 21.67920
## -75.62059 19.96254
##
##
## Species name: allogus
However, ENMTools also contains some sample data. It contains an enmtools.clade object called “iberolacerta.clade”, which holds several enmtools.species objects. It also has some low-resolution Worldclim data that we can use to demonstrate functions. We’ll pull two of those species out now.
data(iberolacerta.clade)
data(euro.worldclim)
monticola <- iberolacerta.clade$species$monticola
cyreni <- iberolacerta.clade$species$cyreni
env <- euro.worldclim
ENMTools contains functions to simplify the ENM construction process. Using enmtools.species objects and the correct modeling commands, we can build models very quickly. These commands are primarily wrappers to dismo model construction and projection functions, and at present are only available for GLM, Maxent, Domain, and Bioclim models. One of the nice bits about this setup is that it allows enmtools to automatically generate suitability maps, do model evaluation, and plot the marginal suitability of habitat for each variable separately.
Before we get started modeling, however, we might want to trim our predictor set so as to reduce collinearity. ENMTools contains a couple of handy functions for this.
raster.cor.matrix(env)
## bio1 bio2 bio3 bio4 bio5 bio6
## bio1 1.00000000 0.208715969 0.36766171 -0.21357041 0.8853513 0.93295069
## bio2 0.20871597 1.000000000 0.58362743 0.30918934 0.5417192 -0.01723188
## bio3 0.36766171 0.583627431 1.00000000 -0.56601419 0.3052211 0.42521254
## bio4 -0.21357041 0.309189341 -0.56601419 1.00000000 0.1754180 -0.52131150
## bio5 0.88535133 0.541719174 0.30522110 0.17541802 1.0000000 0.68751772
## bio6 0.93295069 -0.017231880 0.42521254 -0.52131150 0.6875177 1.00000000
## bio7 -0.05329392 0.709020870 -0.14900115 0.87998888 0.4016817 -0.38884596
## bio8 0.24945265 0.068562982 -0.16262988 0.30400935 0.2862188 0.09285337
## bio9 0.73849291 0.183148800 0.42195497 -0.37866158 0.6400464 0.77343845
## bio10 0.96045067 0.311324869 0.21975162 0.06247355 0.9606340 0.80726704
## bio11 0.95921479 0.101719882 0.48107648 -0.47305206 0.7533941 0.98896057
## bio12 -0.60846674 -0.482731496 -0.31488066 -0.07961919 -0.7137513 -0.48704454
## bio13 -0.41433559 -0.510317568 -0.25626002 -0.19124801 -0.5722885 -0.28138429
## bio14 -0.72871981 -0.338229901 -0.37618609 0.16712793 -0.7297745 -0.67564389
## bio15 0.45421260 -0.007931916 0.11838593 -0.21759678 0.3821863 0.47445069
## bio16 -0.44597594 -0.506032477 -0.26995545 -0.16924912 -0.5920746 -0.31485467
## bio17 -0.70338945 -0.343806007 -0.33935275 0.10832583 -0.7243068 -0.63769389
## bio18 -0.81091065 -0.331213024 -0.47078459 0.28348226 -0.7776879 -0.80126262
## bio19 -0.12414066 -0.396445432 0.07348362 -0.48121938 -0.3430162 0.07715578
## bio7 bio8 bio9 bio10 bio11 bio12
## bio1 -0.05329392 0.24945265 0.7384929 0.96045067 0.95921479 -0.60846674
## bio2 0.70902087 0.06856298 0.1831488 0.31132487 0.10171988 -0.48273150
## bio3 -0.14900115 -0.16262988 0.4219550 0.21975162 0.48107648 -0.31488066
## bio4 0.87998888 0.30400935 -0.3786616 0.06247355 -0.47305206 -0.07961919
## bio5 0.40168174 0.28621877 0.6400464 0.96063401 0.75339408 -0.71375135
## bio6 -0.38884596 0.09285337 0.7734384 0.80726704 0.98896057 -0.48704454
## bio7 1.00000000 0.24603268 -0.1633540 0.20071994 -0.29134540 -0.29133189
## bio8 0.24603268 1.00000000 -0.2200483 0.33135353 0.12985480 -0.30622476
## bio9 -0.16335400 -0.22004834 1.0000000 0.66175815 0.78861884 -0.46297347
## bio10 0.20071994 0.33135353 0.6617581 1.00000000 0.84907884 -0.65829840
## bio11 -0.29134540 0.12985480 0.7886188 0.84907884 1.00000000 -0.54163405
## bio12 -0.29133189 -0.30622476 -0.4629735 -0.65829840 -0.54163405 1.00000000
## bio13 -0.37121605 -0.19351156 -0.3074562 -0.48860809 -0.32972845 0.90648180
## bio14 -0.07381576 -0.25699492 -0.6265099 -0.71411350 -0.72423144 0.77619752
## bio15 -0.11344874 0.17648853 0.3970693 0.41693023 0.49288586 -0.24313910
## bio16 -0.35410914 -0.21747973 -0.3274923 -0.51511693 -0.36513899 0.91789736
## bio17 -0.11473790 -0.30488093 -0.5552129 -0.70368996 -0.68356379 0.80791339
## bio18 0.02381502 0.03291308 -0.8163353 -0.76592247 -0.82992875 0.76402046
## bio19 -0.53249335 -0.51356967 0.1072073 -0.26914814 0.01511498 0.74717071
## bio13 bio14 bio15 bio16 bio17 bio18
## bio1 -0.4143356 -0.72871981 0.454212596 -0.4459759 -0.7033895 -0.81091065
## bio2 -0.5103176 -0.33822990 -0.007931916 -0.5060325 -0.3438060 -0.33121302
## bio3 -0.2562600 -0.37618609 0.118385927 -0.2699555 -0.3393528 -0.47078459
## bio4 -0.1912480 0.16712793 -0.217596785 -0.1692491 0.1083258 0.28348226
## bio5 -0.5722885 -0.72977455 0.382186338 -0.5920746 -0.7243068 -0.77768793
## bio6 -0.2813843 -0.67564389 0.474450688 -0.3148547 -0.6376939 -0.80126262
## bio7 -0.3712161 -0.07381576 -0.113448735 -0.3541091 -0.1147379 0.02381502
## bio8 -0.1935116 -0.25699492 0.176488534 -0.2174797 -0.3048809 0.03291308
## bio9 -0.3074562 -0.62650986 0.397069264 -0.3274923 -0.5552129 -0.81633533
## bio10 -0.4886081 -0.71411350 0.416930231 -0.5151169 -0.7036900 -0.76592247
## bio11 -0.3297284 -0.72423144 0.492885864 -0.3651390 -0.6835638 -0.82992875
## bio12 0.9064818 0.77619752 -0.243139096 0.9178974 0.8079134 0.76402046
## bio13 1.0000000 0.48404051 0.130409758 0.9902335 0.5245850 0.58835234
## bio14 0.4840405 1.00000000 -0.743674332 0.5012004 0.9859234 0.84673991
## bio15 0.1304098 -0.74367433 1.000000000 0.1244492 -0.7294802 -0.46226779
## bio16 0.9902335 0.50120043 0.124449153 1.0000000 0.5362200 0.61586400
## bio17 0.5245850 0.98592339 -0.729480228 0.5362200 1.0000000 0.81764699
## bio18 0.5883523 0.84673991 -0.462267795 0.6158640 0.8176470 1.00000000
## bio19 0.7906993 0.31690226 0.128299899 0.7920907 0.3839700 0.17654879
## bio19
## bio1 -0.12414066
## bio2 -0.39644543
## bio3 0.07348362
## bio4 -0.48121938
## bio5 -0.34301616
## bio6 0.07715578
## bio7 -0.53249335
## bio8 -0.51356967
## bio9 0.10720732
## bio10 -0.26914814
## bio11 0.01511498
## bio12 0.74717071
## bio13 0.79069926
## bio14 0.31690226
## bio15 0.12829990
## bio16 0.79209065
## bio17 0.38396995
## bio18 0.17654879
## bio19 1.00000000
That’s great, but it’s a bit hard to pick variables this way. Let’s try it visually instead.
raster.cor.plot(env)
## $cor.mds.plot
##
## $cor.heatmap
The raster.cor.plot function gives us two visualizations. One heatmap that colors pairs of predictors by their Pearson correlation coefficient, and one cluster plot that does mds scaling of the predictor variables and then plots them in a two dimensional space so that more correlated predictors are closer to each other. We’re going to make an arbitrary decision to just use three predictors, and to keep those predictors relatively uncorrelated we’ll select predictors that are far apart in this mds plot. Here we’ll choose bio1, bio12, and bio7.
env <- env[[c("bio1", "bio12", "bio7")]]
plot(env)
raster.cor.matrix(env)
## bio1 bio12 bio7
## bio1 1.00000000 -0.6084667 -0.05329392
## bio12 -0.60846674 1.0000000 -0.29133189
## bio7 -0.05329392 -0.2913319 1.00000000
GLMs usually require the user to supply a formula, an enmtools.species object, and some environmental data. If your formula is a strictly additive function of all of the environmental layers in env, though, enmtools.glm will build a formula automatically.
monticola.glm <- enmtools.glm(species = monticola, env = env, f = pres ~ bio1 + bio12 + bio7, test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
monticola.glm
##
##
## Formula: presence ~ bio1 + bio12 + bio7
## <environment: 0x7fe806d1f0a8>
##
##
## Data table (top ten lines):
##
## Longitude Latitude bio1 bio12 bio7 presence
## --- ---------- --------- ----- ------ ----- ---------
## 2 -6.036635 43.02531 76 1012 246 1
## 3 -7.679727 40.38852 137 1143 247 1
## 4 -7.790437 40.30959 129 1231 242 1
## 5 -7.473340 43.78935 140 931 179 1
## 6 -6.575039 42.91070 84 1012 247 1
## 7 -5.132756 43.49572 133 822 190 1
## 9 -4.941888 43.35310 128 843 194 1
## 10 -7.621731 40.34170 101 1514 229 1
## 11 -7.645674 40.36543 101 1514 229 1
## 12 -7.642539 40.36317 101 1514 229 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)], weights = weights)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.6042 -0.7922 -0.5140 0.8634 2.1569
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 8.364e+00 2.205e+00 3.794 0.000148 ***
## bio1 -3.366e-02 6.503e-03 -5.176 2.26e-07 ***
## bio12 3.435e-05 7.136e-04 0.048 0.961606
## bio7 -1.981e-02 5.011e-03 -3.954 7.69e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 576.70 on 719 degrees of freedom
## Residual deviance: 515.94 on 716 degrees of freedom
## AIC: 254.48
##
## Number of Fisher Scoring iterations: 4
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 512
## AUC : 0.7258489
## cor : 0.301858
## max TPR+TNR at : 0.03665443
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 10000
## AUC : 0.4230673
## cor : -0.01993855
## max TPR+TNR at : 0.5090876
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 512
## AUC : 0.7622446
## cor : 0.2118952
## max TPR+TNR at : 0.00180972
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 10000
## AUC : 0.4336135
## cor : -0.004969639
## max TPR+TNR at : 0.5003774
##
##
## Suitability:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 0.03082304, 0.995713 (min, max)
##
##
##
## Notes:
Notice this produces the same formula as:
monticola.glm <- enmtools.glm(species = monticola, env = env, test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
monticola.glm
##
##
## Formula: presence ~ bio1 + bio12 + bio7
## <environment: 0x7fe802ed64a0>
##
##
## Data table (top ten lines):
##
## Longitude Latitude bio1 bio12 bio7 presence
## --- ---------- --------- ----- ------ ----- ---------
## 1 -5.171215 43.06957 78 917 249 1
## 3 -7.679727 40.38852 137 1143 247 1
## 6 -6.575039 42.91070 84 1012 247 1
## 7 -5.132756 43.49572 133 822 190 1
## 8 -7.787378 40.39362 137 1143 247 1
## 9 -4.941888 43.35310 128 843 194 1
## 10 -7.621731 40.34170 101 1514 229 1
## 11 -7.645674 40.36543 101 1514 229 1
## 12 -7.642539 40.36317 101 1514 229 1
## 14 -7.950000 43.30000 120 1200 194 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)], weights = weights)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.6289 -0.8022 -0.5004 0.8633 2.2402
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 8.7725133 2.2308281 3.932 8.41e-05 ***
## bio1 -0.0343084 0.0066734 -5.141 2.73e-07 ***
## bio12 0.0001268 0.0007217 0.176 0.86
## bio7 -0.0216427 0.0050313 -4.302 1.70e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 576.70 on 719 degrees of freedom
## Residual deviance: 510.02 on 716 degrees of freedom
## AIC: 249.56
##
## Number of Fisher Scoring iterations: 4
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 512
## AUC : 0.727755
## cor : 0.3130125
## max TPR+TNR at : 0.08339971
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 10000
## AUC : 0.4193312
## cor : -0.01737421
## max TPR+TNR at : 0.5001451
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 512
## AUC : 0.7313702
## cor : 0.1867733
## max TPR+TNR at : 0.07584635
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 10000
## AUC : 0.424925
## cor : -0.008521652
## max TPR+TNR at : 0.5001451
##
##
## Suitability:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 0.02445751, 0.9966599 (min, max)
##
##
##
## Notes:
If you want a more complicated formula, though (e.g., with interactions or polynomial effects), you’ll need to supply that manually.
monticola.glm <- enmtools.glm(species = monticola, env = env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) * poly(bio12, 2), test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
monticola.glm
##
##
## Formula: presence ~ poly(bio1, 2) + poly(bio7, 2) + poly(bio12, 2) + poly(bio7,
## 2):poly(bio12, 2)
## <environment: 0x7fe80d6e3bd0>
##
##
## Data table (top ten lines):
##
## Longitude Latitude bio1 bio12 bio7 presence
## --- ---------- --------- ----- ------ ----- ---------
## 1 -5.171215 43.06957 78 917 249 1
## 2 -6.036635 43.02531 76 1012 246 1
## 3 -7.679727 40.38852 137 1143 247 1
## 4 -7.790437 40.30959 129 1231 242 1
## 5 -7.473340 43.78935 140 931 179 1
## 7 -5.132756 43.49572 133 822 190 1
## 8 -7.787378 40.39362 137 1143 247 1
## 10 -7.621731 40.34170 101 1514 229 1
## 11 -7.645674 40.36543 101 1514 229 1
## 12 -7.642539 40.36317 101 1514 229 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)], weights = weights)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.3380 -0.7258 -0.3885 0.6687 2.6688
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -0.7339 0.3856 -1.903 0.0570 .
## poly(bio1, 2)1 -31.2086 5.8448 -5.340 9.32e-08 ***
## poly(bio1, 2)2 -31.1678 6.3797 -4.885 1.03e-06 ***
## poly(bio7, 2)1 -29.7091 12.3332 -2.409 0.0160 *
## poly(bio7, 2)2 9.5133 10.3674 0.918 0.3588
## poly(bio12, 2)1 20.1612 12.0709 1.670 0.0949 .
## poly(bio12, 2)2 -6.6204 9.4210 -0.703 0.4822
## poly(bio7, 2)1:poly(bio12, 2)1 75.0788 412.7961 0.182 0.8557
## poly(bio7, 2)2:poly(bio12, 2)1 -293.9872 282.9726 -1.039 0.2988
## poly(bio7, 2)1:poly(bio12, 2)2 311.8559 274.7100 1.135 0.2563
## poly(bio7, 2)2:poly(bio12, 2)2 204.1818 167.7220 1.217 0.2235
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 576.70 on 719 degrees of freedom
## Residual deviance: 451.97 on 709 degrees of freedom
## AIC: 240.37
##
## Number of Fisher Scoring iterations: 5
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 512
## AUC : 0.7906494
## cor : 0.4141145
## max TPR+TNR at : 0.04282543
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 208
## n absences : 10000
## AUC : 0.6829697
## cor : 0.09426448
## max TPR+TNR at : 0.5106297
##
##
## Proportion of data wittheld for model fitting: 0.2
##
## Model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 512
## AUC : 0.7864333
## cor : 0.2563593
## max TPR+TNR at : 0.4823131
##
##
## Environment space model fit (test data): class : ModelEvaluation
## n presences : 52
## n absences : 10000
## AUC : 0.6883154
## cor : 0.04769127
## max TPR+TNR at : 0.2717871
##
##
## Suitability:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 2.220446e-16, 0.948588 (min, max)
##
##
##
## Notes:
To check out the marginal response functions, you only need to type
monticola.glm$response.plots
## $bio1
##
## $bio7
##
## $bio12
These plots present a smoothed estimate of the frequency of different levels of the environemntal variable in the presence data and the background points, along with the estimated relationship between that environmental predictor and the suitability of habitat from the model.
You can also visualize your models and data in a 2D environment space using any pair of layers from your environment stack. These plots hold all non-plotted variables (bio7 in this case) constant at their mean value across all presence points, then vary the plotted variables between the minimum and maximum values in env.
The suit.plot shows you suitability in environment space as a function of your two variables, with brighter colors representing variable combinations predicted to be more suitable. The points represent the occurrence points for your species in that environment space.
The colored raster of the background.plot shows you the density of background points in environment space, while the white points again represent your occurrence points in environment space.
visualize.enm(monticola.glm, env, layers = c("bio1", "bio12"), plot.test.data = TRUE)
## $background.plot
## Warning: Removed 396 rows containing missing values (geom_raster).
##
## $suit.plot
The procedure for building Bioclim, Domain, and Maxent models is similar to the procedure for GLMs, with the exception that you do not need to pass a formula to the model function for Maxent, Domain, and Bioclim models. Note that running Maxent models requires a bit of extra setup; see dismo documentation for details.
monticola.gam <- enmtools.gam(monticola, env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) * poly(bio12, 2), test.prop = 0.2)
monticola.dm <- enmtools.dm(monticola, env, test.prop = 0.2)
monticola.bc <- enmtools.bc(monticola, env, test.prop = 0.2)
monticola.mx <- enmtools.maxent(monticola, env, test.prop = 0.2)
ENMTools provides a number of metrics for ENMs and for similarities between ENMs. These include measures of niche breadth, based on Levins(1968). An important caveat when interpreting these metrics is that they are driven to some (variable) extent by the availability of different combinations of environmental predictors. As such they are more accurately interpreted as a measurment of the smoothness of the geographic distribution of suitability scores than as an estimate of the breadth of the fundamental niche; an organism with narrow fundamental niche breadth that nonetheless encompasses a set of environmental conditions that is quite common will have a high breadth when measured using ENMs, while having a low breadth in environment space.
raster.breadth(monticola.glm)
## $B1
## [1] 0.9467639
##
## $B2
## [1] 0.5479248
ENMTools also provides metrics for measuring similarity between ENMs. These include Schoener’s D (Schoener 1968), I (Warren et al. 2008), and the Spearman rank correlation coefficient between two rasters. While D and I are commonly used in the ENM literature, they may tend to overestimate similarity between ENMs when many grid cells are of similar values (e.g., when two species prefer different habitat but the region contains a great deal of habitat that is unsuitable for both).
monticola.glm <- enmtools.glm(species = monticola, env = env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) + poly(bio12, 2), test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
cyreni.glm <- enmtools.glm(species = cyreni, env = env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) + poly(bio12, 2), test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
raster.overlap(monticola.glm, cyreni.glm)
## $D
## [1] 0.6665115
##
## $I
## [1] 0.8824732
##
## $rank.cor
## [1] 0.2980151
A new feature of the R version of ENMTools is that you can now use these same metrics in the n-dimensional space of all combinations of environmental variables, instead of restricting your measures of model similarity to those sets of conditions that appear in the training region. This is done by repeatedly drawing Latin hypercube samples from the space of all possible combinations of environmental variables given the min and max of each variable within the training region. ENMTools continues to draw samples until subsequent iterations differ by less than a specified tolerance value. Lower tolerance values result in more precise estimates of overlap, but can take much longer to calculate.
monticola.glm <- enmtools.glm(species = monticola, env = env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) + poly(bio12, 2), test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
cyreni.glm <- enmtools.glm(species = monticola, env = env, f = pres ~ poly(bio1, 2) + poly(bio7, 2) + poly(bio12, 2), test.prop = 0.2)
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
env.overlap(monticola.glm, cyreni.glm, env, tolerance = .001)
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## $env.D
## [1] 0.9248497
##
## $env.I
## [1] 0.9935104
##
## $env.cor
## [1] 0.9965278
##
## $env.D.plot
##
## $env.I.plot
##
## $env.cor.plot
The plots that come out of these environment space functions are used for diagnosing convergence of the overlap/breadth metric. Ideally what you want is a relationship between the metric and the number of samples that shows no clear directional trend.
In this example, we will run a niche identity (also called equivalency) test, as in Warren et al. 2008. This test takes the presence points for a pair of species and randomly reassigns them to each species, then builds ENMs for these randomized occurrences. By doing this many times, we can estimate the probability distribution for ENM overlap between species under the null hypothesis that the two species’ occurrences in the environment are effectively a random draw from the same underlying distribution. Note that niche evolution is only one of many reasons why two species’ realized environmental distributions might cause departures from this null hypothesis. See Warren et al. 2014 for details.
To run an identity test, we need to decide what type of models we will build, how many replicates we will run, and (in the case of GLM and GAM) a model formula to use for empirical models and the Monte Carlo replicates. The resulting object contains the replicate models, p values, and plots of the results. Typically idenity tests are run with at least 99 replicates, but we are using a smaller number here for the sake of execution time.
NOTE: In order for models to be comparable, both empirical and pseudoreplicate models for the identity test are conducted with pseudoabsence points pooled for the two species being compared.
id.glm <- identity.test(species.1 = monticola, species.2 = cyreni, env = env, type = "glm", nreps = 4)
id.glm
##
##
##
##
## Identity test monticola vs. cyreni
##
## objectentity test p-values:
## D I rank.cor env.D env.I env.cor
## 0.2 0.2 0.2 0.2 0.2 0.2
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ---------- ---------- ---------- ----------
## empirical 0.3244487 0.5929443 0.1049357 0.3683738 0.6162005 0.1366267
## rep 1 0.9542630 0.9980737 0.9982316 0.9796806 0.9990537 0.9990559
## rep 2 0.9359663 0.9962068 0.9962758 0.9729271 0.9986184 0.9973418
## rep 3 0.9802523 0.9995308 0.9957173 0.9787928 0.9994803 0.9973746
## rep 4 0.9406985 0.9964928 0.9909815 0.9666267 0.9981988 0.9911703
The background or similarity test compares the overlap seen between two species’ ENMs to the overlap expected by chance if one or both species was effectively choosing habitat at random from within their broad geographic range. The purpose of this test is to correct for the availability of habitat and ask whether the observed similarity between species or populations is significantly more (or less) than expected given the available set of environments in the regions in which they occur.
NOTE: In order for models to be comparable, both empirical and pseudoreplicate models for the background test are conducted with pseudoabsence points pooled for the two species being compared.
In Warren et al. 2008, we developed this test in the context of comparing one species’ actual occurrence to the random background occurrences of the other species. This is what we call an “asymmetric” test, and in our case we did the test in both directions with the idea that we might compare the results of A vs. B background to the results of B vs. A background. This may be informative in some cases, but many people have also found this asymmetry confusing (and indeed it is often difficult to interpret). For that reason, the background test here can be conducted against a null hypothesis that is generated from “asymmetric” (species.1 vs species.2 background) or “symmetric” (species.1 background vs. species.2 background) comparisons.
Here, for instance, is a Bioclim background test using the classical asymmetric approach:
bg.bc.asym <- background.test(species.1 = monticola, species.2 = cyreni, env = env, type = "bc", nreps = 4, test.type = "asymmetric" )
bg.bc.asym
##
##
##
##
## Asymmetric background test
## monticola vs. cyreni background
##
## background test p-values:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.4 0.4 0.4 0.4
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- ----------
## empirical 0.0242365 0.1455829 -0.0450249 0.0138121 0.1101811 0.1580886
## rep 1 0.6347801 0.8831796 0.7259586 0.5355100 0.7892334 0.6756080
## rep 2 0.6919520 0.9141597 0.8093257 0.5576398 0.7931825 0.6611715
## rep 3 0.6341818 0.8833161 0.7255914 0.5173982 0.7799887 0.6590816
## rep 4 0.5969304 0.8514780 0.6238979 0.4600689 0.7309414 0.6456313
And here is a Domain background test using the symmetric approach:
bg.dm.sym <- background.test(species.1 = monticola, species.2 = cyreni, env = env, type = "dm", nreps = 4, test.type = "symmetric" )
bg.dm.sym
##
##
##
##
## Symmetric background test
## monticola background vs. cyreni background
##
## background test p-values:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.4 0.4 0.4 0.4
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- ----------
## empirical 0.1974048 0.4272913 -0.1020590 0.0785594 0.2661434 0.2225575
## rep 1 0.9594044 0.9969784 0.7949358 0.8314754 0.9438534 0.9517038
## rep 2 0.9441451 0.9945936 0.7583155 0.7827718 0.9210024 0.9247136
## rep 3 0.9285920 0.9913858 0.7765214 0.7455506 0.8938092 0.9349658
## rep 4 0.9195126 0.9898710 0.5791306 0.7470834 0.8948964 0.9235197
Using enmtools.species objects also provides a simplified interface to the niche equivalency and similarity tests (or identity and background tests, respectively) that were developed by Broennimann et al. (2012). These tests do not rely on ENMs, instead using kernel density smoothing to estimate density of the species in environment space. Ecospat also uses the density of the available environment to correct for availability when measuring overlaps, so that overlaps are not strictly driven by availability of combinations of environmental variables.
These tests only work with two environmental axes, so they are often done with the top two PC axes of a set of environments. In our case we’ll just pick a couple of environmental layers, though (bio1 and bio2). Here’s an equivalency/identity test:
esp.id <- enmtools.ecospat.id(monticola, cyreni, env[[c("bio1", "bio12")]])
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
esp.id
##
##
##
##
## Ecospat identity test monticola vs. cyreni
##
## ecospat.id test empirical overlaps:
## $D
## [1] 0.0477392
##
## $I
## [1] 0.2097866
##
##
##
## ecospat.id test p-values:
## D I
## 0 0
## NULL
And here’s a symmetric background test. The difference between symmetric and asymmetric for these tests is the same as for the background tests presented above.
esp.bg.sym <- enmtools.ecospat.bg(monticola, cyreni, env[[c("bio1", "bio12")]], test.type = "symmetric")
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
esp.bg.sym
##
##
##
##
## Ecospat background test symmetric monticola vs. cyreni
##
## ecospat.bg test empirical overlaps:
## $D
## [1] 0.0477392
##
## $I
## [1] 0.2097866
##
##
##
## ecospat.bg test p-values:
## D I
## 0.54 0.44
## NULL
Note that if you provide more than two layers to the enmtools.ecospat function, it will performa a PCA analysis on the provided layers and measure overlaps on the first two axes of that PCA space.
esp.bg.sym <- enmtools.ecospat.bg(monticola, cyreni, env, test.type = "symmetric")
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
##
## [1] "More than two layers in environment stack and no layers argument passed, performing PCA..."
esp.bg.sym
##
##
##
##
## Ecospat background test symmetric monticola vs. cyreni
##
## ecospat.bg test empirical overlaps:
## $D
## [1] 0.01293428
##
## $I
## [1] 0.109648
##
##
##
## ecospat.bg test p-values:
## D I
## 0.52 0.44
## NULL
ENMTools also allows you to perform linear, blob, and ribbon rangebreak tests as developed in Glor and Warren 2011. The linear and blob tests are two versions of a test that permit one to ask whether the geographic regions occupied by two species are more environmentally different than expected by chance. The ribbon test, meanwhile, is designed to test whether the ranges of two species are divided by a region that is relatively unsuitable to one or both forms.
For the linear and blob tests, you call them very much like you would the identity and background tests. Here’s a linear one using GLM models:
rbl.glm <- rangebreak.linear(monticola, cyreni, env, type = "glm", nreps = 4)
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
##
##
## Building empirical models...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Building replicate models...
##
## Replicate 1 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 2 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 3 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 4 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
rbl.glm
##
##
##
##
## Linear rangebreak test monticola vs. cyreni
##
## rangebreak test p-values:
## D I rank.cor env.D env.I env.cor
## 0.2 0.2 0.6 0.2 0.2 0.6
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- ----------
## empirical 0.3244487 0.5929443 0.1049357 0.3687690 0.6165354 0.1385839
## rep 1 0.4238586 0.7145215 0.2216069 0.4560899 0.7114940 0.4373129
## rep 2 0.4899984 0.7817582 -0.0685635 0.5719161 0.7941241 0.0815886
## rep 3 0.4921653 0.7819151 -0.0472656 0.5772411 0.7972295 0.1244706
## rep 4 0.5623162 0.8226942 0.7311974 0.6952123 0.8610592 0.7879526
And here’s a blob test using Bioclim:
rbb.bc <- rangebreak.blob(monticola, cyreni, env, type = "bc", nreps = 4)
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
##
##
## Building empirical models...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Building replicate models...
##
## Replicate 1 ...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 2 ...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 3 ...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 4 ...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
rbb.bc
##
##
##
##
## blob rangebreak test monticola vs. cyreni
##
## rangebreak test p-values:
## D I rank.cor env.D env.I env.cor
## 1.0 1.0 1.0 1.0 1.0 0.8
##
##
## Replicates:
##
##
## D I rank.cor env.D env.I env.cor
## ---------- ---------- ---------- ----------- ---------- ---------- ----------
## empirical 0.0242365 0.1455829 -0.0450249 0.0149374 0.1147606 0.1635571
## rep 1 0.0242365 0.1455829 -0.0450249 0.0146145 0.1133825 0.1624760
## rep 2 0.0242365 0.1455829 -0.0450249 0.0137484 0.1104227 0.1600984
## rep 3 0.0242365 0.1455829 -0.0450249 0.0124557 0.1052408 0.1532283
## rep 4 0.0242365 0.1455829 -0.0450249 0.0145834 0.1135235 0.1635659
If you want to access the individual replicates (for instance to see how your ranges are being split up), you can find them in the list named “replicate.models” inside your rangebreak test object.
rbl.glm$replicate.models$monticola.rep.1
##
##
## Formula: presence ~ bio1 + bio12 + bio7
## <environment: 0x7fe80338d2e0>
##
##
## Data table (top ten lines):
##
## Longitude Latitude bio1 bio12 bio7 presence
## ---------- --------- ----- ------ ----- ---------
## -9.06 42.86 133 1144 160 1
## -9.06 42.86 133 1144 160 1
## -8.07 43.75 134 1045 166 1
## -8.07 43.66 135 1048 168 1
## -7.94 43.75 131 1061 171 1
## -7.95 43.66 129 1080 176 1
## -8.32 43.31 138 1099 174 1
## -8.32 43.31 138 1099 174 1
## -8.20 43.40 140 1038 164 1
## -8.20 43.40 140 1038 164 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)], weights = weights)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -1.8899 -0.7538 -0.3885 0.7078 1.8568
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 8.606610 2.190390 3.929 8.52e-05 ***
## bio1 -0.041172 0.006590 -6.248 4.17e-10 ***
## bio12 0.001204 0.000715 1.684 0.0921 .
## bio7 -0.021344 0.004851 -4.400 1.08e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 720.87 on 901 degrees of freedom
## Residual deviance: 583.19 on 898 degrees of freedom
## AIC: 272.39
##
## Number of Fisher Scoring iterations: 5
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 260
## n absences : 642
## AUC : 0.7839384
## cor : 0.3943522
## max TPR+TNR at : -0.4575054
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 260
## n absences : 10000
## AUC : 0.4261215
## cor : -0.008340168
## max TPR+TNR at : 0.3875015
##
##
## Proportion of data wittheld for model fitting: 0
##
## Model fit (test data): [1] NA
##
##
## Environment space model fit (test data): [1] NA
##
##
## Suitability:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 0.0122167, 0.9996632 (min, max)
##
##
##
## Notes:
rbl.glm$replicate.models$cyreni.rep.1
##
##
## Formula: presence ~ bio1 + bio12 + bio7
## <environment: 0x7fe807b8d8b0>
##
##
## Data table (top ten lines):
##
## Longitude Latitude bio1 bio12 bio7 presence
## ---------- --------- ----- ------ ----- ---------
## -5.29 40.31 89 646 296 1
## -5.29 40.31 89 646 296 1
## -5.18 40.41 85 625 294 1
## -5.18 40.41 85 625 294 1
## -5.07 40.50 85 605 295 1
## -5.17 40.36 85 625 294 1
## -5.29 40.22 89 646 296 1
## -5.29 40.22 89 646 296 1
## -5.18 40.32 89 646 296 1
## -5.17 40.23 89 646 296 1
##
##
## Model:
## Call:
## glm(formula = f, family = "binomial", data = analysis.df[, -c(1,
## 2)], weights = weights)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -0.68147 -0.37151 -0.18616 -0.00872 2.15658
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 3.342734 10.180288 0.328 0.7426
## bio1 -0.097650 0.018047 -5.411 6.27e-08 ***
## bio12 -0.008124 0.003370 -2.410 0.0159 *
## bio7 0.041124 0.029909 1.375 0.1691
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 210.72 on 847 degrees of freedom
## Residual deviance: 134.05 on 844 degrees of freedom
## AIC: 69.086
##
## Number of Fisher Scoring iterations: 7
##
##
##
## Model fit (training data): class : ModelEvaluation
## n presences : 76
## n absences : 772
## AUC : 0.8644839
## cor : 0.2724207
## max TPR+TNR at : -0.531141
##
##
## Environment space model fit (training data): class : ModelEvaluation
## n presences : 76
## n absences : 10000
## AUC : 0.8118776
## cor : 0.1086662
## max TPR+TNR at : 0.3276855
##
##
## Proportion of data wittheld for model fitting: 0
##
## Model fit (test data): [1] NA
##
##
## Environment space model fit (test data): [1] NA
##
##
## Suitability:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : layer
## values : 2.311685e-07, 0.9816987 (min, max)
##
##
##
## Notes:
For the ribbon rangebreak test, you will need one extra thing; a third enmtools.species object representing the occurrence points (for one or both species) that fall within the ribbon of putatively unsuitable habitat. In the case of these two lizards we don’t have such a ribbon, so we’ll just simulate one based on some random points.
plot(env[[1]])
points(cyreni$presence.points, col = "red")
points(monticola$presence.points, col = "blue")
ribbon <- enmtools.species(species.name = "ribbon")
ribbon$presence.points <- data.frame(Longitude = runif(n = 10, min = -9, max = 0),
Latitude = runif(n = 10, min = 40.5, max = 42))
points(ribbon$presence.points, pch = 16)
ribbon$range <- background.raster.buffer(ribbon$presence.points, 20000, mask = env)
ribbon
##
##
## Range raster:
## class : RasterLayer
## dimensions : 54, 162, 8748 (nrow, ncol, ncell)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -10, 17, 39, 48 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
## source : memory
## names : bio1
## values : 1, 1 (min, max)
##
##
##
## Presence points (first ten only):
##
## Longitude Latitude
## ---------- ---------
## -6.129220 40.72542
## -7.890325 41.02556
## -7.739593 41.33454
## -4.058920 41.66140
## -4.025198 41.98360
## -6.702123 41.12854
## -8.461674 40.58375
## -6.109484 41.90445
## -2.343359 41.14968
## -6.953375 40.68837
##
##
## Background points not defined.
##
## Species name: ribbon
Now we’ll run a ribbon rangebreak test using GLM models with quadratic effects. We also need to tell it the width of the ribbons to generate for the replicates. The units for the width argument are the same units that the presence points are in; e.g., if the points are in decimal degrees you should supply the width of the barrier in decimal degrees.
rbr.glm <- rangebreak.ribbon(monticola, cyreni, ribbon, env, type = "glm", f = pres ~ poly(bio1, 2) + poly(bio12, 2) + poly(bio7, 2), width = 0.5, nreps = 4)
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
##
##
##
## No background points provided, drawing background from range raster.
##
##
## Building empirical models...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Building replicate models...
##
## Replicate 1 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 2 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 3 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
##
## Replicate 4 ...
##
##
## Drawing background from species background points.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species ribbon
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## Drawing background from species background points.
##
## Adding environmental data to species outside
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
## [1] "Trying to find starting conditions, attempt 1"
## [1] "Building replicates..."
rbr.glm
##
##
##
##
## ribbon rangebreak test monticola vs. cyreni
##
## rangebreak test p-values...
##
## Species 1 vs. Species 2:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 1.2 0.4 0.4 0.4
##
## Species 1 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 1.2 1.2 0.8 0.8 0.8 1.2
##
## Species 2 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 0.4 0.4 0.4 0.4 0.4 0.4
##
## Outside vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## 0.8 1.2 0.8 0.8 0.8 1.2
##
##
## Replicates:
##
## Species 1 vs. Species 2:
## D I rank.cor env.D env.I env.cor
## empirical 0.1046659 0.2985999 -0.09341571 0.1427600 0.2710862 0.070442125
## rep 1 0.2749392 0.5213698 -0.02909554 0.1979577 0.3472836 -0.096524093
## rep 2 0.1898499 0.4137553 -0.25337005 0.2363244 0.3946712 -0.006604097
## rep 3 0.3527579 0.6078922 -0.09726463 0.2843750 0.4387362 0.002121358
## rep 4 0.3612984 0.6363904 0.05679828 0.1850580 0.3618047 -0.133679321
##
## Species 1 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## empirical 0.5085292 0.7758681 -0.1499291 0.18585122 0.3750015 0.2534375
## rep 1 0.5887749 0.8450684 0.6159389 0.37166501 0.6024888 0.3887710
## rep 2 0.5474636 0.8172383 0.7324182 0.57902325 0.7568744 0.7293525
## rep 3 0.4419450 0.6763826 -0.4907316 0.27083969 0.4668480 -0.2510016
## rep 4 0.2898986 0.5026428 -0.0460609 0.08497594 0.1501441 -0.5148241
##
## Species 2 vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## empirical 0.1910484 0.4293908 0.1339280 0.05850246 0.1025010 -0.3922290
## rep 1 0.6278257 0.8158874 0.6274195 0.72193355 0.8346663 0.7381670
## rep 2 0.3759968 0.5897905 0.2846720 0.43456827 0.6412360 0.6060878
## rep 3 0.6524993 0.8832473 0.8516774 0.76908507 0.9150089 0.9500528
## rep 4 0.5860599 0.7757038 0.6498462 0.58815477 0.7002735 0.5051720
##
## Outside vs. Ribbon:
## D I rank.cor env.D env.I env.cor
## empirical 0.5519232 0.8072924 -0.1578581 0.2287552 0.4347165 0.2537613
## rep 1 0.7427112 0.9333799 0.8426549 0.5222271 0.7469359 0.4661590
## rep 2 0.5248211 0.8079108 0.7471912 0.5408752 0.7495544 0.6550672
## rep 3 0.4995095 0.7149333 -0.2740587 0.3356039 0.5325945 -0.1581800
## rep 4 0.3899846 0.6235863 0.1743041 0.1873108 0.2996731 -0.3956902
Note that the output table here has slope, intercept, and intercept offset.
rbr.glm$lines.df
## slope intercept offset
## 1 -0.53633288 38.50450 0.2836870
## 2 3.48313587 58.84971 0.9059607
## 3 -6.07468347 12.43720 1.5391105
## 4 -0.08938415 40.43230 0.2509967
The intercept denotes the intercept corresponding to the CENTER of each ribbon. To get the lines denoting the edges of the ribbons (for example if you want to plot the ribbons on a map), you add and substract the offset. In other words, the top edge of the ribbon is given by y = (slope * x) + intercept + offset, while the bottom edge is given by y = (slope * x) + intercept - offset.
Some of the tests in ENMTools, including some really neat ones that are still in development, require you to build an enmtools.clade object. These objects are simply lists that contain a phylogeny and a set of enmtools.species objects. It’s important that the names of the species objects and their species.name attributes match the names in the phylogeny’s tip.labels. For demonstration, we’re going to build an object for a clade of five anoles from Hispaniola. We have the tree, so we’re just going to grab occurrence data from GBIF using the rgbif package.
library(rgbif)
library(ape)
hisp.anoles <- read.nexus(file = "./testdata/StarBEAST_MCC.species.txt")
keepers <- c("brevirostris", "marron", "caudalis", "websteri", "distichus")
hisp.anoles <- drop.tip(phy = hisp.anoles, tip = hisp.anoles$tip.label[!hisp.anoles$tip.label %in% keepers])
plot(hisp.anoles)
So there’s our tree. Now we’re going to grab some environmental data.
hisp.env <- stack(list.files("./testdata/Hispaniola_Worldclim", full.names = TRUE))
hisp.env <- setMinMax(hisp.env)
And then we’ll create a function to build species from GBIF.
# Automate the process of downloading data and removing duds and dupes
species.from.gbif <- function(genus, species, name = NA, env){
# Name it after the species epithet unless told otherwise
if(is.na(name)){
name <- species
}
# Get GBIF data
this.sp <- enmtools.species(presence.points = gbif(genus = genus, species = species)[,c("lon", "lat")],
species.name = name)
# Rename columns, get rid of duds
colnames(this.sp$presence.points) <- c("Longitude", "Latitude")
this.sp$presence.points <- this.sp$presence.points[complete.cases(extract(env, this.sp$presence.points)),]
this.sp$presence.points <- this.sp$presence.points[!duplicated(this.sp$presence.points),]
this.sp$range <- background.raster.buffer(this.sp$presence.points, 50000, mask = hisp.env)
return(this.sp)
}
Now we’ll create five species and add them to a species.clade object that is called brev.clade.
brevirostris <- species.from.gbif(genus = "Anolis", species = "brevirostris", env = hisp.env)
marron <- species.from.gbif(genus = "Anolis", species = "marron", env = hisp.env)
caudalis <- species.from.gbif(genus = "Anolis", species = "caudalis", env = hisp.env)
websteri <- species.from.gbif(genus = "Anolis", species = "websteri", env = hisp.env)
distichus <- species.from.gbif(genus = "Anolis", species = "distichus", env = hisp.env)
brev.clade <- enmtools.clade(species = list(brevirostris, marron, caudalis, websteri, distichus), tree = hisp.anoles)
check.clade(brev.clade)
##
##
## An enmtools.clade object with 5 species
##
## Species names:
## brevirostris caudalis distichus marron websteri
##
## Tree:
##
## Phylogenetic tree with 5 tips and 4 internal nodes.
##
## Tip labels:
## [1] "brevirostris" "caudalis" "distichus" "marron" "websteri"
##
## Rooted; includes branch lengths.
##
##
## Data Summary:
##
##
## species.names in.tree presence background range
## ------------- -------------- -------- --------- ----------- --------
## brevirostris brevirostris TRUE 187 0 present
## caudalis caudalis TRUE 21 0 present
## distichus distichus TRUE 780 0 present
## marron marron TRUE 13 0 present
## websteri websteri TRUE 18 0 present
That’s one way to build a clade object by hand, but there’s already one built into ENMTools to experiment with so we’ll just use that.
data(iberolacerta.clade)
The AOC tests allow you to examine patterns of range, point, and ENM overlap in the context of a phylogeny. This is effectively a generalized version of several analyses: age-range correlation (e.g., Fitzpatrick and Turelli 2006), ENM overlap in the context of a phylogeny (e.g., Knouft et al. 2006, Warren et al. 2008), and point overlaps (e.g., Cardillo and Warren 2016).
These tests require the creation of an enmtools.clade object, as above. AOC tests consist of two steps: first, the average overlap at each node in the phylogeny is calcualted using a method that takes tree topology into account (see Fitzpatrick and Turelli 2006), then we perform a linear regression to measure the relationship between node age and average overlap. Due to the fact that these overlaps violate many of the assumptions of a regular linear regression, however (e.g., errors are not iid), we can’t calculate significance in the typical way. Instead we performa Monte Carlo test, permuting the identity of the tips of the tree and repeating the node averaging and modeling steps. Finally we measure statistical significance by comparing the empirical slope and intercept to the distribution of slopes and intercepts from the Monte Carlo replicates.
First, let’s do one using geog.range.overlaps, as in Fitzpatrick and Turelli 2006. Note that this analysis requires that each of your species have a range raster stored in their species object (we did that as part of the function used above).
range.aoc <- enmtools.aoc(clade = iberolacerta.clade, nreps = 50, overlap.source = "range")
summary(range.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) empirical.df$age
## 0.03921569 0.03921569
## NULL
Now we can do one using point overlaps just by changing the overlap.source argument:
point.aoc <- enmtools.aoc(clade = iberolacerta.clade, nreps = 50, overlap.source = "points")
summary(point.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) empirical.df$age
## 0.4313725 0.4705882
## NULL
Or we can use similarity between ENMs built for each species. Here we’ll use GLM models:
glm.aoc <- enmtools.aoc(clade = iberolacerta.clade, env = env, nreps = 50, overlap.source = "glm", f = pres ~ poly(bio1, 2) + poly(bio12, 2))
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species monticola
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species martinezricai
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species cyreni
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species horvathi
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species aurelioi
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species aranica
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
##
##
##
## No background points provided, drawing background from range raster.
##
## Adding environmental data to species bonnali
## Processing presence points...
## Processing background points...
##
##
## Drawing background from species background points.
summary(glm.aoc)
##
##
## Age-Overlap Correlation test
##
## 50 replicates
##
## p values:
## (Intercept) empirical.df$age
## 0.2352941 0.2745098
## NULL
Broennimann, O., Fitzpatrick, M. C., Pearman, P. B., Petitpierre, B., Pellissier, L., Yoccoz, N. G., Thuiller, W., Fortin, M.-J., Randin, C., Zimmermann, N. E., Graham, C. H. and Guisan, A. (2012), Measuring ecological niche overlap from occurrence and spatial environmental data. Global Ecology and Biogeography, 21: 481–497. doi:10.1111/j.1466-8238.2011.00698.x
Fitzpatrick, B. M., & Turelli, M. (2006). The geography of mammalian speciation: mixed signals from phylogenies and range maps. Evolution, 60(3), 601-615.
Knouft, J. H., Losos, J. B., Glor, R. E., & Kolbe, J. J. (2006). Phylogenetic analysis of the evolution of the niche in lizards of the Anolis sagrei group. Ecology, 87(sp7).
Levins, R. 1968. Evolution In Changing Environments. Monographs in Population Biology, volume 2. Princeton University Press, Princeton, New Jersey, USA.
Schoener, T. W. 1968. Anolis lizards of Bimini: resource partitioning in a complex fauna. Ecology 49:704- 726.
Warren, D.L., R.E. Glor, and M. Turelli. 2008. Environmental niche identity versus conservatism: quantitative approaches to niche evolution. Evolution 62:2868-2883. doi: 10.1111/j.1558-5646.2008.00482.x
Warren, D.L., M. Cardillo, D.F. Rosauer, and D.I. Bolnick. 2014. Mistaking geography for biology: inferring processes from species distributions. Trends in Ecology and Evolution 29 (10), 572-580. doi: 10.1016/j.tree.2014.08.003
Warren, D.L., L. Beaumont, R. Dinnage, and J. Baumgartner. 2019. New methods for measuring ENM breadth and overlap in environmental space. Ecography. Doi: 10.1111/ecog.03900